#ifdef HAVE_CONFIG_H
#        include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "mainwindow.h"


#define GLADE_HOOKUP_OBJECT(component,widget,name) \
        g_object_set_data_full (G_OBJECT (component), name, \
                gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
        g_object_set_data (G_OBJECT (component), name, widget)

GtkWidget* 
create_window_main ( struct file_ctrl *global_file,struct clist_struct *clist)
{
        GdkPixbuf *window_main_icon_pixbuf;
        GtkWidget *vbox_main; /*this split main window into three areas*/
        
        GtkWidget *menubar;
        
        GtkWidget *toolbar;
        
        GtkWidget *hbox_main;/*split thrid vbox_main area into tow areas*/

	GtkWidget *clist_show;
	GtkWidget *clist_group;
        GtkWidget *statusbar; /*status bar*/
        GtkAccelGroup *accel_group;
        GtkTooltips *tooltips;

        tooltips = gtk_tooltips_new ();

        accel_group = gtk_accel_group_new ();
	/*create main window*/
        window_main = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title (GTK_WINDOW (window_main), _("EasyBlog"));
        gtk_window_set_default_size (GTK_WINDOW (window_main), 800, 600);
	window_main_icon_pixbuf = create_pixbuf ("ico-window.png");
  	if (window_main_icon_pixbuf)
        {
      		gtk_window_set_icon (GTK_WINDOW (window_main), window_main_icon_pixbuf);
     		 gdk_pixbuf_unref (window_main_icon_pixbuf);
    	}

        vbox_main = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox_main);
        gtk_container_add (GTK_CONTAINER (window_main), vbox_main);
        GTK_WIDGET_SET_FLAGS (vbox_main, GTK_CAN_FOCUS);
	
	menubar=(GtkWidget *)create_menubar(window_main,vbox_main,tooltips,accel_group);
	
        toolbar=(GtkWidget *)create_toolbar(window_main,vbox_main,tooltips);
        
        hbox_main = gtk_hbox_new (FALSE, 0);
        gtk_widget_show (hbox_main);
        gtk_box_pack_start (GTK_BOX (vbox_main), hbox_main, TRUE, TRUE, 0);
	
	clist_group=(GtkWidget *)create_clist_group(window_main,hbox_main);
	clist_show=(GtkWidget *)create_clist_show(window_main,hbox_main);
        
        statusbar = gtk_statusbar_new ();
        gtk_widget_show (statusbar);
        gtk_box_pack_start (GTK_BOX (vbox_main), statusbar, FALSE, FALSE, 0);
        gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);

        g_signal_connect ((gpointer) window_main, "delete_event",
                                                                                G_CALLBACK (on_window_main_delete),
                                                                                (gpointer)global_file);
        
             			                                                                   
        /* Store pointers to all widgets, for use by lookup_widget(). */
        GLADE_HOOKUP_OBJECT_NO_REF (window_main, window_main, "window_main");
        GLADE_HOOKUP_OBJECT (window_main, vbox_main, "vbox_main");
             
        GLADE_HOOKUP_OBJECT (window_main, hbox_main, "hbox_main");
        GLADE_HOOKUP_OBJECT (window_main, statusbar, "statusbar");
        GLADE_HOOKUP_OBJECT_NO_REF (window_main, tooltips, "tooltips");

        gtk_window_add_accel_group (GTK_WINDOW (window_main), accel_group);
	init_clist_struct(clist);
        clist->clist_show=clist_show;
        clist->show_all_row=&global_file->cur_file->info_nums;
        clist->clist_group=clist_group;
        clist->group_all_row=&global_file->group_nums;
        clist->statusbar=statusbar;
        return window_main;
}

